package com.wisdytech.ccdserver.bucket.serveice.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wisdytech.ccdserver.bucket.dao.IBucketRelationDao;
import com.wisdytech.ccdserver.bucket.model.BucketRelation;
import com.wisdytech.ccdserver.bucket.serveice.IBucketRelationService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.CollectionUtils;

import java.io.Serializable;
import java.util.*;
import java.util.stream.Collectors;


@Slf4j
public class BucketRelationServiceImpl extends ServiceImpl<IBucketRelationDao, BucketRelation> implements IBucketRelationService {


    /**
     * @Description: 将配置的数据处理成map集合，提供后面面遍历时使用。
     * @Param: * @param filter
     * @return: * @return java.util.Map<java.lang.String,com.wisdytech.ccdserver.bucket.model.BucketRelation>
     * @Author: SV00216491
     * @Date: 2024/4/17  14:28
     */
    @Override
    public Map<String, BucketRelation> dealListToMap() {
        List<BucketRelation> list = this.baseMapper.selectList(null);
        if (CollectionUtils.isEmpty(list)) {
            return Collections.EMPTY_MAP;
        }
        Map<String, BucketRelation> relationMap = list.stream().collect(Collectors.toMap(br -> br.getLineCode() + "-" + br.getOpCode(), br -> br));
        return relationMap;
    }

    @Override
    public List<String> dealListToList() {
        List<BucketRelation> list = this.baseMapper.selectList(null);
        if (CollectionUtils.isEmpty(list)) {
            return Collections.EMPTY_LIST;
        }
        return list.stream().map(br -> br.getLineCode() + "-" + br.getOpCode()).collect(Collectors.toList());
    }
}
